using Core;

namespace g_gongjianta
{
    using MainFSM = battle.fsm.MainFSM<battle.fsm.anchor.WholeLayer>;

    public class Anchor : Unit, ICharacter, IAwake<TblDungeon.WallConf>
    {
        public TblAnchor.Conf Conf { get; private set; }
        public TblSkill TblSkill { get; private set; }

        public Bow Bow { get; private set; }

        public AnchorMainComponent Main { get; private set; }
        public MainFSM FSM { get; private set; }

        public void Awake(TblDungeon.WallConf wallConf)
        {
            base.Awake();

            Conf = G.Table.GetSO<TblAnchor>().Find(wallConf.AnchorID);
            Name = Conf.Name;
            TblSkill = Conf.Skill;

#if UNITY_EDITOR
            gameObject.name = $"Anchor_{Conf.Id}_{InstanceId}";
#endif
            var visualParam = new VisualParam
            {
                Path = Global.UNIT_PREFAB_PATH,
                Icon = Conf.Icon,
            };

            Add<EventComponent>();
            Add<VisualComponent, VisualParam>(visualParam);
            Add<SenseComponent, string>(wallConf.BtnCode);
            Add<SkillComponent>();
            Add<AnchorEventHandler>();

            FSM = Add<MainFSM>();
            Main = Add<AnchorMainComponent>();

            
            Bow = G.Factory.Create<Bow, TblAnchor.WeaponConf>(Conf.weapon);
            Bow.transform.SetParent(transform);
            Bow.transform.Reset();
            Bow.transform.localPosition = Conf.weapon.Offset;
        }
    }
}